import java.util.*;

/**
 * @author LKQ
 * @date 2022/6/11 11:40
 * @description
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int N = sc.nextInt();
            TreeMap<Integer, Integer> treeMap = new TreeMap<>();
            for (int i = 0; i < N; i++) {
                int key = sc.nextInt(), value = sc.nextInt();
                if (treeMap.containsKey(key)) {
                    treeMap.put(key, treeMap.get(key) + value);
                }else {
                    treeMap.put(key, value);
                }
            }
            for (Map.Entry<Integer, Integer> entry : treeMap.entrySet()) {
                System.out.print(entry.getKey() + " " + entry.getValue() + "\n");
            }
        }
    }
}
